Skip to main content

StringKeyDictionary<TValue>

StringKeyDictionary<TValue>

StringKeyDictionary represents a dictionary collection of models. Unlike RealtimeDictionary, StringKeyDictionary is transactional. This means that models are not added to the collection until they are confirmed by the server. If any key has been modified before your change reaches the server, it will be rejected. It is up to your application to decide whether to retry the operation. Adding or removing items sends the minimal amount of information to the server in order to perform the update on all clients. The whole collection is not sent every time. Once a key has been added, it is assigned a unique ID by the server to reduce bandwidth for future updates.

Events

didInsertModelForKey

event DidInsertModelForKey<TValue> didInsertModelForKey

An event that fires when a model is successfully added to the collection by any client.

didRemoveModelForKey

event DidRemoveModelForKey<TValue> didRemoveModelForKey

An event that fires when a model is successfully removed from the collection by any client.

didClearAllModels

event DidClearAllModels<TValue> didClearAllModels

An event that fires when the collection is cleared by any client.

Properties

Item

TValue Item { get; }

Retrieve a model given a specific key.

  • key:The key of the model to retrieve
  • Count

    int Count { get; }

    The number of models currently stored in the collection.

    Methods

    Insert

    void Insert(string key, TValue value, Action<bool> completionHandler)

    Insert a model into the collection. The model will not be inserted until the server confirms the transaction.

  • key:The key to use to store the model.
  • value:The model to store in the collection. This value cannot be null.
  • completionHandler:A completion handler that fires when the operation is complete along with a boolean to indicate if the transaction was successful.
  • Remove

    void Remove(string key, Action<bool> completionHandler)

    Remove a model from the collection. The model will not be removed until the server confirms the transaction.

  • key:The key of the model to remove.
  • completionHandler:A completion handler that fires when the operation is complete along with a boolean to indicate if the transaction was successful.
  • Clear

    void Clear(Action<bool> completionHandler)

    Clear all models from the collection. Models will not be removed until the server confirms the transaction.

    This operation will be rejected if any keys have been modified before the clear operation reaches the server.

  • completionHandler:A completion handler that fires when the operation is complete along with a boolean to indicate if the transaction was successful.
  • TryGetValue

    bool TryGetValue(string key, TValue& value)

    Attempt to retrieve a value from the collection.

    This method will not throw an exception if the key is not found.

    A boolean indicating whether the key was found within the collection.

  • key:The key of the model to fetch.
  • value:The model if one is found, otherwise null.
  • ContainsKey

    bool ContainsKey(string key)

    Check if a key exists within the collection.

    A boolean indicating whether the key was found within the collection.

  • key:The key to search for.
  • ContainsValue

    bool ContainsValue(TValue value)

    Check if a model instance is contained in the collection.

    This method has equivalent performance to Dictionary<T, V>.ContainsValue().

    A boolean indicating whether the value was found within the collection.

  • value:The RealtimeModel instance to look for.
  • GetEnumerator

    IEnumerator<KeyValuePair<string, TValue>> GetEnumerator()

    GetCollectionTypeID

    uint GetCollectionTypeID()